﻿using DbModel.Models;
using IRepositories;
using Microsoft.EntityFrameworkCore;
using MyEntityFramework;
using Repositories.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Repositories
{
    public class ArticleRepository : BaseRepository<Article>, IArticleRepository
    {
        public ArticleRepository(MyDbContext myDb) : base(myDb)
        {

        }

        public Task<Article> GetByIdAsync(int id, CancellationToken cancellationToken = default)
        {
            return DbContext().Article.Where(x=>x.Id== id)
                .Include(x=>x.ArticleComments).ThenInclude(x=>x.CreateUser).SingleOrDefaultAsync(cancellationToken);
        }

        public Task<Article> GetCollectionArticlesByIdAsync(int id, CancellationToken cancellationToken = default)
        {
            return DbContext().Article.Where(x => x.Id == id).Include(x => x.CollectionArticles).SingleOrDefaultAsync(cancellationToken);
        }
    }
}
